package com.rxnetwork.sample.login

import android.util.Log
import android.widget.TextView
import android.widget.Toast

import com.rxnetwork.bus.RxBus
import com.rxnetwork.sample.R
import com.rxnetwork.sample.mvp.MVPBaseActivity

class LoginActivity : MVPBaseActivity<LoginContract.MyView, LoginPresenter>(), LoginContract.MyView {

    private var mUserName: TextView? = null
    private var mPassword: TextView? = null

    override val contentViewResId: Int
        get() = R.layout.login

    override fun initViewsAndEvents() {
        //不设置，默认白色
        //        setTopBarLayoutColor(getResources().getColor(R.color.color_ffffff));

        mUserName = findViewById(R.id.username) as TextView
        mPassword = findViewById(R.id.password) as TextView

        mPresenter?.showLoading()
        mPresenter?.login(mUserName?.text.toString(), mPassword?.text.toString())

        RxBus.instance.send("rxbusTag", "消息实体")
    }

    override val topTitle: CharSequence
        get() = "Test标题"

    override fun loginSuccess(user: Any) {
        Log.i("test1234", mPresenter?.toString())
        mPresenter?.hideLoading()
        Toast.makeText(this, "user:" + user.toString(), Toast.LENGTH_SHORT).show()

    }

    override fun loginFailed(message: String) {
        mPresenter?.hideLoading()
        Toast.makeText(this, "msg:" + message, Toast.LENGTH_SHORT).show()
    }

}
